﻿using System;
using System.Linq;
using System.Collections.Generic; 
using System.Data;
using Matrix.Common.Utility;
using Matrix.MaKaYunShang.Model;
using Matrix.MaKaYunShang.DAL;
using Matrix.MaKaYunShang.Model.Dto;

namespace Matrix.MaKaYunShang.BLL
{
	public partial class ScanEventBLL : BaseBLL<ScanEventBLL>
	{
		#region 默认方法
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(ScanEvent model)
		{
			return ScanEventDAL.Instance.Add(model);		
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ScanEvent model)
		{
			return ScanEventDAL.Instance.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{			
			return ScanEventDAL.Instance.Delete(Id);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return ScanEventDAL.Instance.DeleteList(Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ScanEvent GetModel(int Id)
		{
			var ds = ScanEventDAL.Instance.GetModel(Id);
            return ds == null ? null : ServicesHelper.DataSetToIList<ScanEvent>(ds).ToList()[0];
		}
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ScanEvent> GetModelList(string strWhere = null)
		{
			var ds = ScanEventDAL.Instance.GetList(strWhere);
			return ServicesHelper.DataSetToIList<ScanEvent>(ds).ToList();
		}

        public List<ScanEventDto> GetList(int scanSource, DateTime starTime, DateTime endTime, string strWhere)
	    {
            var ds = ScanEventDAL.Instance.GetList(scanSource, starTime, endTime,strWhere);
            return ServicesHelper.DataSetToIList<ScanEventDto>(ds).ToList();
	    }

	    #endregion

        #region 扩展方法

        public int GetModelByScanQrContentCount(string scanQrContent, int consumerId)
        {
            return ScanEventDAL.Instance.GetModelByScanQrContentCount(scanQrContent, consumerId);
        }
        /// <summary>
        /// 根据openid查询最后一条抽奖记录
        /// </summary>
        public ScanEvent GetModelByConsumerId(int consumerId)
        {
            DataSet ds = ScanEventDAL.Instance.GetModelByConsumerId(consumerId);
            return ds == null ? null : ServicesHelper.DataSetToIList<ScanEvent>(ds).ToList()[0];
        }
        public ScanEvent GetModelByScanQrContent(int consumerId)
        {
            DataSet ds = ScanEventDAL.Instance.GetModelByScanQrContent(consumerId);
            return ds == null ? null : ServicesHelper.DataSetToIList<ScanEvent>(ds).ToList().FirstOrDefault();
        }

        public ScanEvent GetModelByScanQrContent(string qrContent, int consumerId)
        {
            DataSet ds = ScanEventDAL.Instance.GetModelByScanQrContent(qrContent, consumerId);
            return ds == null ? null : ServicesHelper.DataSetToIList<ScanEvent>(ds).ToList().FirstOrDefault();
        }
        #endregion
	}
}